package com.xncoding.wechat.config;


import com.xncoding.wechat.service.BankCardService;
import com.xncoding.wechat.utils.WXPayUtility;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.security.PublicKey;

@Configuration
public class WxPayConfig {

    @Value("${wxpay.appid}")
    private String appId;

    @Value("${wxpay.appkey}")
    private String appKey;

    @Value("${wxpay.bank.publicKey}")
    private String bankPublicKey;

    @Bean
    public BankCardService bindCardService() {
        try {
            // 加载银行公钥
            PublicKey publicKey = WXPayUtility.loadPublicKeyFromString(bankPublicKey);
            return new BankCardService(appId, appKey, publicKey);

        } catch (Exception e) {
            throw new RuntimeException("初始化绑卡服务失败", e);
        }
    }
}
